<!-- 实验技术要求管理 -->
<template>
  <div>
    <div class="searchbox">
      <el-form :inline="true" size="small" label-width="100px">
        <jt-easy-collapse :has-expand="true">


<template slot="expand">
  <el-form-item label="零件号">
                            <el-input v-model="form.partNumber" placeholder="零件号"></el-input>
                          </el-form-item>
                          <el-form-item label="零件名称">
                            <el-input v-model="form.partName" placeholder="零件名称"></el-input>
                          </el-form-item>
                          <el-form-item label="零件图号">
                            <el-input v-model="form.partGraphNumber" placeholder="零件图号"></el-input>
                          </el-form-item>
                          <el-form-item label="热处理炉号">
                            <el-input v-model="form.heatingNumber" placeholder="热处理炉号"></el-input>
                          </el-form-item>

  <el-form-item label="项目号">
    <el-input v-model="form.projectNo" placeholder="项目号"></el-input>
  </el-form-item>
  <el-form-item label="样品阶段">
    <!-- <el-input v-model="form.sampleStatusPhase" placeholder="样品阶段"></el-input> -->
    <el-select v-model="form.sampleStatusPhase" filterable placeholder="请选择" style="width: 200px;">
                              <el-option  :label="all" :value="' '"></el-option>
      <el-option v-for="item in phaseList" :key="item.code" :label="item.name" :value="item.code"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="材料牌号">
    <el-input v-model="form.materialNo" placeholder="材料牌号"></el-input>
  </el-form-item>
  <el-form-item label="报验批次信息">
    <el-input v-model="form.batchNumber" placeholder="报验批次信息"></el-input>
  </el-form-item>
  <el-form-item style="margin-left: 20px;">
                            <el-button size="mini" type="primary" @click="showList">查询</el-button>
                          </el-form-item>
                          <el-form-item>
                            <el-button size="mini" @click='clearParam'>清除</el-button>
                          </el-form-item>
</template>
        </jt-easy-collapse>
      </el-form>
    </div>
    <div class="contentbox">
      <div style="float: left;padding-left: 20px;font-size: 15px;color: #666;padding-top: 6px;">
        实验技术要求管理信息 共 <span style="color: red;">{{pageTotal}}</span> 条数据
      </div>
      <el-row style="float: right;margin-right: 20px;margin-bottom: 15px;" type="flex" justify="end">
        <el-col>
          <jt-table-column-filter tableName='experimentalTechnology' :table-key.sync="tableKey" :header-data.sync="tableHeaderArr" :filter-column.sync="filterColumnData"></jt-table-column-filter>
          <el-button size="small" type="primary" @click="addOrder">新增</el-button>
          <!-- <el-button size="small" type="primary">导出</el-button> -->
          <el-button size="small" type="primary" @click="getExcel()">导出清单</el-button>
          <!-- <el-button size="small" type="primary">导出报告</el-button> -->
           <el-button size="small" type="primary" @click="deleteBatch">批量删除</el-button>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="tableData" :key='tableKey' v-loading="loading" @selection-change="handleSelectionChange" stripe>
        <el-table-column type="selection" width="50" align="center" :resizable="false"></el-table-column>
        <el-table-column :index="indexMethod" type="index" label="序号" width="50" align="center" :resizable="false"></el-table-column>
        <el-table-column align="center" :key='item' v-for='item in filterColumnData' :resizable="false"
            :label="getTableHeaderLabel(item)"
            :prop="item"
            :min-width="getTableColumnWidth(item)"
            :fixed="getTableColumnFixed(item)"
            :sortable="getTableColumnSort(item)">
<template slot-scope="scope">
   {{scope.row[item]}}
  <el-button v-if="item === 'operate'" size="small" type="text" @click="updateOrder(scope.row)">修改</el-button>
  <el-button v-if="item === 'operate'" size="small" type="text" @click='deletePart(scope.row)'>删除</el-button>
</template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="center">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizeArr"
          :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageTotal"></el-pagination>
      </el-row>

      <tech-requirement :show.sync="isShowAdd" :modifyId='orderId' @refreshAdd="showList"></tech-requirement>
      <!-- <tech-requirement-modify :show.sync="isShowModify" @orderId="orderId"></tech-requirement-modify> -->
    </div>
  </div>
</template>

<script>
  import JtTableColumnFilter from 'components/jt-table-column-filter/index'; // 导入表格列筛选组件
  import JtEasyCollapse from 'components/jt-easy-collapse/index';
  import TechRequirement from 'dialog/resource-management/experimental-technology-requirements-management/editing-technical-requirements-button';
  import TechRequirementModify from 'dialog/resource-management/experimental-technology-requirements-management/editing-technical-requirements-button-modify';
  // import '../../../mock/resource-management/experimental-technology-requirements-management';
  import {
    getPartList,
    deletePart,
    getSampleStatusPhase,
    partAllDelete
  } from 'service/task';
  import {
    getLableFromList
  } from 'utils/common'
  import {
    STATUS_LIST
  } from 'service/constant'
  export default {
    name: 'RemindingCenter',
    components: {
      'jt-table-column-filter': JtTableColumnFilter,
      'jt-easy-collapse': JtEasyCollapse,
      'tech-requirement': TechRequirement,
      'tech-requirement-modify': TechRequirementModify
    },
    data() {
      return {
        tableKey: 1, // table key
        filterColumnData: [],
         selectCount: 0,
          all:'全部',
        tableHeaderArr: [{
            'name': 'partNumber',
            'alias': '零件号',
            'default': true,
            'width': 110,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'partGraphNumber',
            'alias': '零件图号',
            'default': true,
            'width': 170,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'heatingNumber',
            'alias': '热处理炉号',
            'default': false,
            'width': 170,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'partName',
            'alias': '零件名称',
            'default': true,
            'width': 170,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'projectNo',
            'alias': '项目号',
            'default': true,
            'width': 230,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'materialNo',
            'alias': '材料牌号',
            'default': true,
            'width': 230,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'sampleStatusPhaseStr',
            'alias': '样品阶段',
            'default': true,
            'width': 230,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'batchNumber',
            'alias': '报验批次信息',
            'default': true,
            'width': 230,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'statusStr',
            'alias': '启用/禁用',
            'default': true,
            'width': 230,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'remark',
            'alias': '备注',
            'default': true,
            'width': 230,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'operate',
            'alias': '操作',
            'default': true,
            'width': 190,
            'fixed': 'right',
            'sort': false
          }
        ],
        tableData: [],
        form: {
          partNumber: '',
          partName: '',
          partGraphNumber: '',
          heatingNumber: ''
        },
        currentPage: 1,
        pageNumber: 1,
        pageSizeArr: [10, 20, 50, 100],
        pageSize: 10,
        pageTotal: 0,
        loading: false,
        isShowAdd: false,
        isShowModify: false,
        phaseList: [],
        orderId: ''
      }
    },
    mounted() {
      getSampleStatusPhase().then(res => {
        this.phaseList = res.data.result;
      })
      this.showList();
    },
    watch: {
      isShowAdd() {
        if (!this.isShowAdd || !this.isShowModify) {
          this.showList();
        }
      }
    },
    methods: {
       getExcel() {
        window.location.href= `${process.env.API_URL}` + "part/getPartExcel?partNumber=" + this.form.partNumber
        + "&partName=" + this.form.partName + "&partGraphNumber=" + this.form.partGraphNumber + "&heatingNumber=" + this.form.heatingNumber;
      },
       indexMethod(index) {
        return index + this.pageSize * (this.currentPage-1) + 1;
      },
      clearParam() {
        this.form = {};
        this.showList();
      },
      deletePart(row) {
          let confirm = this.$confirm('您确定删除吗?','提示',{
          // confirmButtonText: '确定',
          // cancelButtonText: '取消',
          type: 'warning'
        }).then(res => {
         deletePart([row]).then(res => {
        if (res.data.success) {
         this.$message({
            message: res.data.message,
            type: 'success',
            duration: 1000
            });
          this.showList();
        }
      });
      }).catch(res => {
         return
     });
      },
       deleteBatch() {
if (this.selectCount <= 0) {
        this.$Message.warning("您还未选择要删除的数据");
        return;
      }
      this.$Modal.confirm({
        title: "确认删除",
        content: "您确认要删除所选的 " + this.selectCount + " 条数据?",
        onOk: () => {
          let ids = "";
          this.selectList.forEach(function(e) {
            ids += e.id + ",";
          });
          ids = ids.substring(0, ids.length - 1);
          partAllDelete({ids: ids.split(",")}).then(res => {
            if (res.data.success === true) {
              this.$Message.success("删除成功");
               this.showList();
            }
          });
        }
      });
    },
      // 新增
      addOrder() {
        this.orderId = '';
        this.isShowAdd = true;
      },
      // 编辑
      updateOrder(row) {
        this.orderId = row.id;
        this.isShowAdd = true;
      },
      // 获取表格多选的值
      handleSelectionChange(val) {
          this.selectList = val;
          this.selectCount = val.length;
      },
      // 表格数据展示
      showList() {
        this.loading = true;
        getPartList({
          // this.axios.get('/system/partList', {
          ...this.form,
          pageNumber: this.pageNumber,
          pageSize: this.pageSize,
          sort: '',
          order: ''
        }).then(res => {
          this.tableData = res.data.result.content;
          // this.currentPage = res.data.result.pageable.pageNumber;
          this.pageSize = res.data.result.pageable.pageSize;
          this.pageTotal = res.data.result.totalElements;
          this.loading = false;
          this.tableData.forEach(e => {
            e.sampleStatusPhaseStr = getLableFromList(this.phaseList, e.sampleStatusPhase);
            e.statusStr = getLableFromList(STATUS_LIST, e.status);
          })
        });
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.showList();
      },
      handleCurrentChange(val) {
        this.pageNumber = val;
        this.showList();
      },
      // 表头展示
      getTableHeaderLabel(str) {
        return this.getTableSomeValue(str, 'alias');
      },
      // 获取表格列的宽度
      getTableColumnWidth(str) {
        return this.getTableSomeValue(str, 'width');
      },
      // 获取表格列是否是固定的
      getTableColumnFixed(str) {
        return this.getTableSomeValue(str, 'fixed');
      },
      // 获取表格列是否排序
      getTableColumnSort(str) {
        return this.getTableSomeValue(str, 'sort');
      },
      // 获取表格表头，列宽度，列固定，列排序的值
      getTableSomeValue(str, keyName) {
        for (var value of this.tableHeaderArr) {
          if (value['name'] == str) {
            return value[keyName];
          }
        }
      }
    }
  }
</script>
